package com.hfh.io.exer;

import org.junit.Test;

import java.io.*;

public class Exer3 {
    @Test
    public void test1() throws IOException {
        long l =System.currentTimeMillis();
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("file/最后的人.mp4"));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("file/test2.mp4"));
        byte[] arr = new byte[1024];
        int len;
        while ((len=bis.read(arr))!=-1){
            bos.write(arr,0,len);
        }
        bos.flush();
        bos.close();
        bis.close();
        System.out.println(System.currentTimeMillis()-l);

    }

    @Test
    public void test(){
        long l =System.currentTimeMillis();
        try(InputStream is = new FileInputStream("file/最后的人.mp4");
            OutputStream os = new FileOutputStream("file/test1.mp4")){
            byte[] arr = new byte[1024];
            int len;
            while ((len=is.read(arr))!=-1){
                os.write(arr,0,len);
            }
            os.flush();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println(System.currentTimeMillis()-l);
    }
}
